#Compilazione della libreria


CC = gcc
NVCC = nvcc
LINKER = $(CC)
ARCH=-m64
CFLAGS = $(ARCH) -fpic -g
NVCCFLAGS = $(ARCH) -Xcompiler -fPIC
#folder containing the headers
INCLUDES = -I../include

#Libraries to includes
LIBS =-L/usr/lib/nvidia-current/ -lconfig -lm -lcuda

#define the source files, simply list all the one in the directory
SRCS=$(wildcard *.c)
CUDA_SRCS=$(wildcard *.cu)

# define the C object files 
#
# This uses Suffix Replacement within a macro:
#   $(name:string1=string2)
#         For each word in 'name' replace 'string1' with 'string2'
# Below we are replacing the suffix .c of all words in the macro SRCS
# with the .o suffix
#
OBJS = $(SRCS:.c=.o) $(CUDA_SRCS:.cu=.o)

%.o : %.c
	$(CC) -c $(CFLAGS) $(INCLUDES)  $< -o $@
	#$(CC) -M $(CFLAGS) $(INCLUDES)  $< > $@.dep

%.o : %.cu
	$(NVCC) -c $(NVCCFLAGS) $(INCLUDES) $< -o $@
	#$(NVCC) -M $(CFLAGS) $(INCLUDES) $< > $@.dep
#
# Pick up generated dependency files, and 
# add /dev/null because gmake does not consider
# an empty list to be a list:
#
#include  $(wildcard *.dep) /dev/null

# define the executable file 
MAIN = libjjann$(ARCH)


.PHONY: clean

all:    $(MAIN)
	@echo  Lib Compiled

	
$(MAIN): $(OBJS) 
	#static version
	ar rcs $(MAIN).a $(OBJS)
	#compiling also the dinamic version of the library
	$(LINKER) $(ARCH) -fPIC -shared -o $(MAIN).so $(OBJS) -lcuda
	mv $(MAIN)* ../
	mv $(OBJS) ../obj/
	rm -f *.dep

clean:
	$(RM) ../obj/*.o *~ ../$(MAIN) 
